﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using Microsoft.SharePoint.Administration;
using System.Windows;

namespace SharePointCommander.Model.TreeView
{
    public class SCServiceCollection : SCTreeViewItem<SPServiceCollection>
    {
        public SCServiceCollection(SCTreeViewItem parent, SPServiceCollection services)
            : base(parent, services)
        {
            Header = "Services";
            IsExpanded = false;
            Expanded += new RoutedEventHandler(SCServiceCollection_Expanded);
            ItemsSource = new object[] { null };
        }

        void SCServiceCollection_Expanded(object sender, System.Windows.RoutedEventArgs e)
        {
            TreeViewItem item = e.Source as TreeViewItem;
            if (!item.ItemsSource.OfType<SCService>().Any())
            {
                item.ItemsSource = from s in SPObject select new SCService(this, s);
            }
        }
    }
}
